<?php

class BlockMethod_GetRequest
    extends BlockMethod {

	protected function getDefaultParams() {

		return array("source" => Value::create("list", "GET, POST"));

	}

    public function run() {

        $oParamSourceValue = $this->getParamByName("source");

        $sResult = "<request>";

        if(!$oParamSourceValue->isEmpty()) {

            if($oParamSourceValue->isContains("GET")) {
                $sResult .= $this->sourceToXML("GET", $_GET);
            }

            if($oParamSourceValue->isContains("POST")) {
                $sResult .= $this->sourceToXML("POST", $_POST);
            }

            if($oParamSourceValue->isContains("SESSION")) {
                $sResult .= $this->sourceToXML("SESSION", $_SESSION);
            }

            if($oParamSourceValue->isContains("COOKIE")) {
                $sResult .= $this->sourceToXML("COOKIE", $_COOKIE);
            }

        }

        return $sResult . "</request>";

    }

    private function sourceToXML(
        $sType,
        $aSource
        ) {

        $sResult = "";

        foreach($aSource as $sParamName => $mParamValue) {

            if(is_array($mParamValue)) {
                foreach($mParamValue as $sParamValue) {
                    $sResult .= "<param type=\"" . $sType . "\" name=\"" . $sParamName . "\">" . $sParamValue . "</param>";
                }
            }
            else {
                $sResult .= "<param type=\"" . $sType . "\" name=\"" . $sParamName . "\">" . $mParamValue . "</param>";
            }

        }

        return $sResult;

    }


}

?>